﻿using System;
using System.Collections.Generic;
using System.Text;


using System.Data;
using System.Data.SQLite;
using System.Diagnostics;
using Microsoft.Win32 ;

namespace Util
{
    public class clsSqlite
    {
        private static SQLiteConnection sql_conn = null;
       
        private static string appdataPath;

        public static void InitializeSqlite()
        {
            appdataPath = System.Windows.Forms.Application.StartupPath;


            if (null == clsSqlite.sql_conn)
            {
                clsSqlite.sql_conn = new SQLiteConnection("data source=" + appdataPath + "\\datas\\data.proj;cache size=1048576;pooling=True;page size=8192;default timeout=15");
                clsSqlite.sql_conn.Open();
            }
        }

        public static SQLiteConnection GetSqliteConn()
        {
            appdataPath = System.Windows.Forms.Application.StartupPath;
            if (null == clsSqlite.sql_conn)
            {
                clsSqlite.sql_conn = new SQLiteConnection("data source=" + appdataPath + "\\datas\\data.proj;cache size=1048576;pooling=True;page size=8192;default timeout=15");
                clsSqlite.sql_conn.Open();
            }
            else if (clsSqlite.sql_conn.State == ConnectionState.Closed)
            {
                sql_conn.Open();
            }
            return clsSqlite.sql_conn;
        }

        public static void FinalizeSqlite()
        {
            if (clsSqlite.sql_conn != null)
            {
                clsSqlite.sql_conn.Close();
                clsSqlite.sql_conn = null;
            }
        }
    }
}
